<script setup lang="ts">
import {PUSH_STATE} from "~/const/Maps";

definePageMeta({
  title:'PUSH列表',
  layout:'admin'
})
const route=useRoute();
const [search_domain,...search_suffix]=(route.query.domain as string)?.split('.')??[]
const form=reactive({
  page:1,// 页码
  limit:11,// 每页显示数量
  search_domain:search_domain??'',// 搜索域名
  search_suffix:search_suffix.join('.')??'',// 搜索后缀
  to_user_id:'',// 推送给用户id
  push_state:route.query.state??'',//
});
const {data:list,refresh}=await useServerGet('/west/getPushList',form)
const pushDo=async (row:any,type:string)=>{
  const {code}=await usePost(`/west/${type}`,{id:row.id})
  if(code==200){
    ElMessage.success('操作成功');
    refresh&&refresh();
  }
}

</script>

<template>
  <el-card class="card">
    <div>
      <el-form :model="form" label-width="0" inline class="my" >
        <el-form-item >
          <el-input v-model="form.search_domain" placeholder="请输入域名" clearable></el-input>
        </el-form-item>
        <el-form-item >
          <el-input v-model="form.search_suffix" placeholder="请输入后缀" clearable></el-input>
        </el-form-item>
        <el-form-item >
          <el-input v-model="form.to_user_id" placeholder="请输入用户id" clearable></el-input>
        </el-form-item>
        <el-form-item >
            <el-select v-model="form.state" placeholder="请选择状态" clearable class="w-[150px!important]">
              <el-option :label="label" :value="value" v-for="(label,value) in PUSH_STATE"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item >
          <el-button type="primary" @click="refresh">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :data="list.data.list"
        style="width: 100%"
        align="center"
        :header-cell-style="{'text-align':'center'}"
        :cell-style="{'text-align':'center'}"
         >
        <el-table-column type="expand">
          <template #default="props">
              <el-table :data="props.row.push_domain">
                <el-table-column label="子编号">
                  <template #default="scope">{{ scope.row.id }}</template>
                </el-table-column>
                <el-table-column label="域名">
                  <template #default="scope">{{ scope.row.domain }}</template>
                </el-table-column>
                <el-table-column label="创建时间">
                  <template #default="scope">{{ scope.row.created_at }}</template>
                </el-table-column>
                <el-table-column label="更新时间">
                  <template #default="scope">{{ scope.row.updated_at }}</template>
                </el-table-column>
              </el-table>
          </template>
        </el-table-column>
        <el-table-column label="编号">
          <template #default="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column label="推送给用户id">
          <template #default="scope">{{ scope.row.to_user_id }}</template>
        </el-table-column>
        <el-table-column label="金额">
          <template #default="scope">{{ scope.row.money }}</template>
        </el-table-column>
        <el-table-column label="平台费用">
          <template #default="scope">{{ scope.row.agent_fee }}</template>
        </el-table-column>
        <el-table-column label="状态">
          <template #default="scope">{{ PUSH_STATE[scope.row.state] }}</template>
        </el-table-column>
        <el-table-column label="操作" width="110">
          <template #default="scope">
            <div v-if="scope.row.state==10">
              <div v-if="scope.row.user_id===scope.row.to_user_id" class="flex justify-center">
                <el-button type="primary" @click="pushDo(scope.row,'acceptPush')">接受</el-button>
                <!--                  push-->
                <el-button @click="pushDo(scope.row,'refusePush')" class="ml-0.5">拒绝</el-button>
              </div>
              <div v-else>
                <el-button class="ml-0.5" type="primary" @click="pushDo(scope.row,'cancelPush')">取消</el-button>
              </div>
            </div>
            <div v-else>-</div>

          </template>
        </el-table-column>
      </el-table>
      <MyPage v-model:page="form.page" v-model:perpage="form.limit" v-model:total="list.data.total" @change="refresh"></MyPage>
    </div>
  </el-card>
</template>
<style scoped lang="scss">

</style>